import { _decorator, Component, Node, input, Input, AudioClip } from 'cc';
const { ccclass, property } = _decorator;
import { GameManager, GameStatus } from './GameManager';
import { AudioMgr } from './AudioMgr';

@ccclass('GameMenuUI')
export class GameMenuUI extends Component {
  @property({ type: Node })
  GamePlayUINode: Node
  @property({ type: AudioClip })
  BackgroundAudioClip: AudioClip
  start() {
    input.on(Input.EventType.MOUSE_UP, this.onMouseUp, this)
    AudioMgr.inst.play(this.BackgroundAudioClip)
    this.controlActive()
  }
  onDestroy() {
    input.off(Input.EventType.MOUSE_UP, this.onMouseUp, this)
  }
  update(deltaTime: number) {
  }
  showGameMenuUI() {
    this.node.active = true
  }
  hideGameMenuUI() {
    this.node.active = false
  }
  controlActive() {
    if (GameManager.status === GameStatus.GameMenu) {
      this.showGameMenuUI()
    }
    else {
      this.hideGameMenuUI()
    }
  }
  onMouseUp() {
    if (GameManager.status === GameStatus.GameMenu) {
      GameManager.updateToGamePlay()
      this.GamePlayUINode.active = true
      this.hideGameMenuUI()
    }
  }
}


